package dipl.algorithm.utility.text;

import dipl.algorithm.math.fp.primitive.Point2df;

/**
 * Code generation utilities
 */
public class CodeGeneration {

	//
	// PUBLIC METHODS
	//

	/**
	 * Prints java-code to create given array of <code>Point2d</code>
	 * @param name
	 * @param arr
	 * @return
	 */
	public static String Point2dArrayString( String name, Point2df[] arr ) {
		if( arr == null || arr.length == 0 ) {
			return name+"=null;";
		}
		String str = "";
		int len = arr.length;
		String className = Point2df.class.getSimpleName();
		str += "\n"+className+"[] "+name+" = new "+className+"[] {\n";
		for( int i = 0; i < len; i++ ) {
			if( arr[i] != null ) {
				String sx = Double.toString( arr[i].x ).replace( ',', '.' );
				String sy = Double.toString( arr[i].y ).replace( ',', '.' );
				str += "  new "+className+"( "+sx+", "+sy+" ),\n";
			}
			else {
				str += "  null,\n";
			}
		}
		str += "};\n";
		return str;
	}
}
